package com.pmcc.core.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by syk on 17/6/21.
 */
@Configuration
public class MyWebAppConfig extends WebMvcConfigurerAdapter {

    @Value("${upload.path}")
    private String path;

    @Value("${upload.readPath}")
    private String readPath;

    @Value("${spring.profiles.active}")
    private String springActive;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/*/**.**.js").addResourceLocations("classpath:/static/");

        //配置文件的上传映射路径
        if ("dev".equals(springActive)) {
            registry.addResourceHandler(readPath + "**").addResourceLocations("file:" + path);
        } else {
            registry.addResourceHandler(readPath + "**").addResourceLocations("file:" + path);
        }
        super.addResourceHandlers(registry);
    }

    /**
     * 重写configurePathMatch此方法
     * 设置其参数PathMatchConfigurer的属性UseSuffixPatternMatch值为false
     * 可以让路径中带小数点“.”后面的值不被忽略
     */
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setUseSuffixPatternMatch(false);
    }

}